package com.ssd.controller.consumer;


import com.ssd.entity.Gift;
import com.ssd.entity.GiftExchange;
import com.ssd.entity.dto.request.GiftSeizeReqDTO;
import com.ssd.entity.dto.request.SeizeCouponReqDTO;
import com.ssd.entity.dto.response.GiftPageInfoResDTO;
import com.ssd.service.IGiftExchangeService;
import com.ssd.service.IGiftService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Null;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 用户端-礼品表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@RestController("consumerGiftController")
@RequestMapping("/consumer/gift")
@Api(tags = "用户端-礼品表控制器")
@Validated
public class GiftController {
    @Resource
    private IGiftService giftService;

    /**
     * 查询可礼品列表
     *
     * @param lastId
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lastId", value = "上一次查询最后一张积分记录id"
                    , required = false, dataTypeClass = Long.class)
    })
    @ApiOperation(value = "分页查询礼品列表")
    public List<GiftPageInfoResDTO> queryGiftConsumerForPage(
            @RequestParam(value = "lastId", required = false) Long lastId) {
        return giftService.queryGiftConsumerForPage(lastId);
    }

    /**
     * 用户兑换商品接口
     *
     * @param giftSeizeReqDTO
     */
    @ApiOperation(value = "兑换礼品接口")
    @PostMapping("/seize")
    public void seizeGift(@RequestBody GiftSeizeReqDTO giftSeizeReqDTO) throws IOException {
            giftService.seizeGift(giftSeizeReqDTO);
    }



    /**
     * 根据礼品id查看礼品详情
     *
     * @param id 礼品id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据礼品id查看礼品详情")
    public Gift getDetail(@PathVariable("id")@Null(message = "礼品id为空，请输入礼品id") Long id) {
        return giftService.getById(id);
    }
}
